﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using SCRUM.Core.Configuration;

namespace SCRUM.Core.MembershipProviders
{
    /// <summary>
    /// Provider for commands taken from XML file
    /// </summary>
    public static class CommandResources
    {
        /// <summary>
        /// XML document
        /// </summary>
        private static XmlDocument doc;

        /// <summary>
        /// Initializes the <see cref="CommandResources"/> class.
        /// </summary>
        static CommandResources() 
        {
            doc = new XmlDocument();
            doc.Load(Path.Combine(
                AppDomain.CurrentDomain.BaseDirectory + ConfigManager.CurrentConfig.MembershipDBProviderXml,
                String.Format("{0}.xml", MembershipProviderFactory.MembershipProvider.Name))); 
        }

        /// <summary>
        /// Gets the command by XPath location.
        /// </summary>
        /// <param name="location">The XPath location.</param>
        /// <returns>Command text</returns>
        public static string GetCommand(string location)
        {
            XmlNode commandNode = doc.SelectSingleNode("/commands/" + location);
            return commandNode.InnerText;
        }
    }
}
